﻿#include <QApplication>
#include <mainwindow.h>
#include <loghelper.h>
#include <dbHelper.h>
#include <amplprogramwindow.h>
#include <amplstepwindow.h>
#include <samplewindow.h>
#include <experimentprowindow.h>
#include <tcpclient.h>
#include <QThread>
#include <StringListener.h>
#include <dataanalysiswindow.h>
#include <experimentinfowindow.h>
#include <experimenttemperaturewindow.h>
#include <setuptotalwind.h>
#include <setup1wind.h>
#include <setup2wind.h>
#include <setup3wind.h>
#include <setup4wind.h>
#include <setup5wind.h>
#include <setup6wind.h>
#include <setup7wind.h>
#include <errmessage.h>
#include <maco.h>
#include <maintainpassword.h>
#include <tcpServer.h>
#include <QMessageBox>
#include "tcts.h"
#include "ui_tcts.h"

int main(int argc, char *argv[])
{
    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
    QApplication a(argc, argv);
    SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);// 防止睡眠

    int fontId = QFontDatabase::addApplicationFont(":/FontStyle/AlibabaPuHuiTi-3-55-Regular.ttf");
    if (fontId != -1) {
        QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
        if (!fontFamilies.isEmpty()) {
            QString familyName = fontFamilies.first();
            QFont font(familyName);
            a.setFont(font);
        }
    }

    // 使用共享内存检查实例
    QSharedMemory shared_memory;
    shared_memory.setKey(QString("123465"));
    if (shared_memory.attach()) {
        QMessageBox::information(nullptr,"提示","软件已经启动");
        qWarning("Another instance is already running.");
        return 0;
    }
    if (!shared_memory.create(1)) {
        qWarning("Failed to create shared memory segment.");
        return -1;
    }

    QString softName="CardType-Chip Analysis Software V1.8";

    TcpClient *tcpClient;

    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    db.transaction();
    QString sql="Create Table IF Not Exists IsFirstStartUp("
                "IsFirst Text,"
                "GuideStatus NUMERIC);";
    query.exec(sql);


    sql="CREATE TABLE IF NOT EXISTS AmplProgram ("
        "Id          TEXT    PRIMARY KEY,"
        "IsDefault   TEXT,"
        "ProgramName TEXT,"
        "Duration    TEXT,"
        "StepNum     INTEGER,"
        "CreateDate  TEXT,"
        "Memo        TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS AmplStep ("
        "Id            TEXT    PRIMARY KEY,"
        "ProgramId     TEXT,"
        "StepNum       INTEGER,"
        "Temperature   NUMERIC,"
        "ExecutionTime TEXT,"
        "Rate          INTEGER,"
        "IsCollect     TEXT,"
        "CycleNumber   TEXT,"
        "CycleNum      INTEGER);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS AmplProgramTemp ("
        "Id          TEXT    PRIMARY KEY,"
        "IsDefault   TEXT,"
        "ProgramName TEXT,"
        "Duration    TEXT,"
        "StepNum     INTEGER,"
        "CreateDate  TEXT,"
        "Memo        TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS AmplStepTemp ("
        "Id            TEXT    PRIMARY KEY,"
        "ProgramId     TEXT,"
        "StepNum       INTEGER,"
        "Temperature   NUMERIC,"
        "ExecutionTime TEXT,"
        "Rate          INTEGER,"
        "IsCollect     TEXT,"
        "CycleNumber   TEXT,"
        "CycleNum      INTEGER);";
    query.exec(sql);


    sql="CREATE TABLE IF NOT EXISTS ConnectionInfo ("
        "Ip   TEXT,"
        "Port INTEGER,"
        "SerialPort TEXT,"
        "BaudRate   TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS ExperimentInfo ("
        "ID             TEXT,"
        "ExperimentName TEXT,"
        "AmplGuid       TEXT,"
        "Code           TEXT,"
        "System         TEXT,"
        "RunTime        TEXT,"
        "Status         TEXT,"
        "FinishTime     TEXT,"
        "ConsumableType TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS FluorescenceData ("
        "SampleId       TEXT,"
        "PositionNumber NUMERIC,"
        "CyclesNumber   NUMERIC,"
        "FAM            TEXT,"
        "VIC            TEXT,"
        "ROX            TEXT,"
        "CY5            TEXT,"
        "AccessFive     TEXT,"
        "AccessSix      TEXT,"
        "AccessSeven    TEXT,"
        "AccessEight    TEXT);";
    query.exec(sql);

    sql="Create Index fDataIndex ON FluorescenceData(SampleId)";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS FluorescenceLvBoData ("
        "SampleId       TEXT,"
        "PositionNumber NUMERIC,"
        "CyclesNumber   NUMERIC,"
        "FAM            TEXT,"
        "VIC            TEXT,"
        "ROX            TEXT,"
        "CY5            TEXT,"
        "AccessFive     TEXT,"
        "AccessSix      TEXT,"
        "AccessSeven    TEXT,"
        "AccessEight    TEXT);";
    query.exec(sql);

    sql="Create Index flvDataIndex ON FluorescenceLvBoData(SampleId)";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS FluorescenceLvboTempTable ("
        "SampleID     TEXT,"
        "CyclesNumber TEXT,"
        "AccessType   TEXT,"
        "AccessVal    TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS FluorescenceLvData ("
        "SampleId       TEXT,"
        "PositionNumber NUMERIC,"
        "CyclesNumber   NUMERIC,"
        "FAM            TEXT,"
        "VIC            TEXT,"
        "ROX            TEXT,"
        "CY5            TEXT,"
        "AccessFive     TEXT,"
        "AccessSix      TEXT,"
        "AccessSeven    TEXT,"
        "AccessEight    TEXT);";
    query.exec(sql);

    sql="Create Index flvDataIndex ON FluorescenceLvData(SampleId)";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS FluorescenceNormalData ("
        "SampleId       TEXT,"
        "PositionNumber NUMERIC,"
        "CyclesNumber   NUMERIC,"
        "FAM            TEXT,"
        "VIC            TEXT,"
        "ROX            TEXT,"
        "CY5            TEXT,"
        "AccessFive     TEXT,"
        "AccessSix      TEXT,"
        "AccessSeven    TEXT,"
        "AccessEight    TEXT);";
    query.exec(sql);

    sql="Create Index fnormalDataIndex ON FluorescenceNormalData(SampleId)";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS FluorescenceNormalTempTable ("
        "SampleID     TEXT,"
        "CyclesNumber TEXT,"
        "AccessType   TEXT,"
        "AccessVal    TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS FluorescenceResultTable ("
        "SampleID          TEXT,"
        "AccessType        TEXT,"
        "BaselineValue     TEXT,"
        "Threshold         TEXT,"
        "Efficiency        TEXT,"
        "Slope             TEXT,"
        "CTVal             TEXT,"
        "StandardDeviation TEXT,"
        "RnThreshold       TEXT,"
        "LogThreshold      TEXT,"
        "RnLogThreshold    TEXT,"
        "NormalThreshold   TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS FluorescenceTempTable ("
        "SampleID     TEXT,"
        "CyclesNumber TEXT,"
        "AccessType   TEXT,"
        "AccessVal    TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS ItemCode ("
        "DicCode   INT,"
        "Code      NUMERIC,"
        "Name      TEXT,"
        "IsDefault TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS ItemDic ("
        "DicCode TEXT,"
        "Name    TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS SampleAccessInfo ("
        "Id         TEXT,"
        "SampleGuid TEXT,"
        "AccessName TEXT,"
        "CtValue    TEXT);";
    query.exec(sql);

    sql="Create Index sampleAccessIndex ON SampleAccessInfo(SampleGuid)";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS SampleInfo ("
        "ID             TEXT,"
        "ExperimentGuid TEXT,"
        "ColNum         TEXT,"
        "RowNum         TEXT,"
        "SampleName     TEXT,"
        "SampleType     TEXT,"
        "SampleConc     TEXT,"
        "Pos            NUMERIC);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS Detbia ("
        "td             TEXT,"
        "ka             TEXT,"
        "data_1         TEXT,"
        "data_2         TEXT,"
        "data_3         TEXT,"
        "data_4         TEXT,"
        "data_5         TEXT,"
        "data_max       TEXT,"
        "data_avg       TEXT);";
    query.exec(sql);

    sql="Create Index sampleIndex ON SampleInfo(ID)";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS Settings ("
        "ID             int,"
        "param_1        TEXT,"
        "param_2        TEXT,"
        "param_3        TEXT,"
        "param_4        TEXT,"
        "param_5        TEXT,"
        "param_6        TEXT,"
        "param_7        TEXT,"
        "param_8        TEXT,"
        "param_9        TEXT,"
        "param_10       TEXT,"
        "param_11       TEXT,"
        "param_12       TEXT);";
    query.exec(sql);

    sql="CREATE TABLE FluorescenceLogTempTable ("
        "SampleID     TEXT,"
        "CyclesNumber TEXT,"
        "AccessType   TEXT,"
        "AccessVal    TEXT);";
    query.exec(sql);

    sql="CREATE TABLE FluorescenceLogData ("
        "SampleId       TEXT,"
        "PositionNumber NUMERIC,"
        "CyclesNumber   NUMERIC,"
        "FAM            TEXT,"
        "VIC            TEXT,"
        "ROX            TEXT,"
        "CY5            TEXT,"
        "AccessFive     TEXT,"
        "AccessSix      TEXT,"
        "AccessSeven    TEXT,"
        "AccessEight    TEXT);";
    query.exec(sql);

    sql="CREATE TABLE FluorescenceRnLogTempTable ("
        "SampleID     TEXT,"
        "CyclesNumber TEXT,"
        "AccessType   TEXT,"
        "AccessVal    TEXT);";
    query.exec(sql);

    sql="CREATE TABLE FluorescenceRnLogData ("
        "SampleId       TEXT,"
        "PositionNumber NUMERIC,"
        "CyclesNumber   NUMERIC,"
        "FAM            TEXT,"
        "VIC            TEXT,"
        "ROX            TEXT,"
        "CY5            TEXT,"
        "AccessFive     TEXT,"
        "AccessSix      TEXT,"
        "AccessSeven    TEXT,"
        "AccessEight    TEXT);";
    query.exec(sql);

    sql="CREATE TABLE IF NOT EXISTS Beijingpiancha ("
        "ka               TEXT,"
        "FAM1k            TEXT,"
        "VIC1k            TEXT,"
        "ROX1k            TEXT,"
        "CY51k            TEXT,"
        "FAM2k            TEXT,"
        "VIC2k            TEXT,"
        "ROX2k            TEXT,"
        "CY52k            TEXT,"
        "FAM3k            TEXT,"
        "VIC3k            TEXT,"
        "ROX3k            TEXT,"
        "CY53k            TEXT,"
        "FAM4k            TEXT,"
        "VIC4k            TEXT,"
        "ROX4k            TEXT,"
        "CY54k            TEXT);";
    query.exec(sql);

    sql="Create Table DataAnalyseSetting("
        "isLv Text,"
        "LvType Text,"
        "AnalyseType Text,"
        "YuType Text,"
        "baseType Text,"
        "famBeginNum    TEXT,"
        "famEnd         TEXT,"
        "roxBeginNum    TEXT,"
        "roxEndNum      TEXT,"
        "cy5BeginNum    TEXT,"
        "cy5EndNum      TEXT,"
        "vicBeginNum    TEXT,"
        "vicEndNum      TEXT,"
        "Spe Text,"
        "YuAnalyseType Text)";
    query.exec(sql);



    db.commit();

    sql="Select count(*) Num from IsFirstStartUp";
    query.exec(sql);

    bool isFirstStartUp = false;
    while (query.next()) {
        isFirstStartUp=query.value("Num").toInt()==0;
    }
    query.clear();

    if(isFirstStartUp)//第一次启动
    {
        db.transaction();

        sql="Insert into IsFirstStartUp values('0',5)";
        query.exec(sql);

        sql="Insert into ConnectionInfo values('192.168.40.56','8888','','')";
        query.exec(sql);

        sql="Insert into ItemDic values('1','样本名称')";
        query.exec(sql);

        sql="Insert into ItemDic values('2','样本类型')";
        query.exec(sql);

        sql="Insert into ItemDic values('3','孔位')";
        query.exec(sql);

        sql="INSERT INTO ItemCode (IsDefault,Name,Code,DicCode) "
            "VALUES (1,'Sample1',0,1),"
            "(0,'Sample2',1,1),"
            "(0,'Sample3',2,1),"
            "(0,'Sample4',3,1),"
            "(0,'Sample5',4,1);";
        query.exec(sql);

        sql="INSERT INTO Detbia (td,ka,data_1,data_2,data_3,data_4,data_5,data_max,data_avg) "
            "VALUES ('FAM','A','0','0','0','0','0','0','0'),"
            "('FAM','B','0','0','0','0','0','0','0'),"
            "('FAM','C','0','0','0','0','0','0','0'),"
            "('FAM','D','0','0','0','0','0','0','0'),"
            "('FAM','E','0','0','0','0','0','0','0'),"
            "('FAM','F','0','0','0','0','0','0','0'),"
            "('VIC','A','0','0','0','0','0','0','0'),"
            "('VIC','B','0','0','0','0','0','0','0'),"
            "('VIC','C','0','0','0','0','0','0','0'),"
            "('VIC','D','0','0','0','0','0','0','0'),"
            "('VIC','E','0','0','0','0','0','0','0'),"
            "('VIC','F','0','0','0','0','0','0','0'),"
            "('ROX','A','0','0','0','0','0','0','0'),"
            "('ROX','B','0','0','0','0','0','0','0'),"
            "('ROX','C','0','0','0','0','0','0','0'),"
            "('ROX','D','0','0','0','0','0','0','0'),"
            "('ROX','E','0','0','0','0','0','0','0'),"
            "('ROX','F','0','0','0','0','0','0','0'),"
            "('CY5','A','0','0','0','0','0','0','0'),"
            "('CY5','B','0','0','0','0','0','0','0'),"
            "('CY5','C','0','0','0','0','0','0','0'),"
            "('CY5','D','0','0','0','0','0','0','0'),"
            "('CY5','E','0','0','0','0','0','0','0'),"
            "('CY5','F','0','0','0','0','0','0','0'),"
            "('FAM','合计','-','-','-','-','-','0','0'),"
            "('VIC','合计','-','-','-','-','-','0','0'),"
            "('ROX','合计','-','-','-','-','-','0','0'),"
            "('CY5','合计','-','-','-','-','-','0','0');";
        query.exec(sql);

        sql="INSERT INTO Beijingpiancha (ka,FAM1k,VIC1k,ROX1k,CY51k,FAM2k,VIC2k,ROX2k,CY52k,FAM3k,VIC3k,ROX3k,CY53k,FAM4k,VIC4k,ROX4k,CY54k) "
            "VALUES ('A','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'),"
            "('B','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'),"
            "('C','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'),"
            "('D','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'),"
            "('E','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'),"
            "('F','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');";
        query.exec(sql);

        sql="INSERT INTO ItemCode (IsDefault,Name,Code,DicCode)"
            "VALUES (1,'未知',0,2),"
            "(0,'标准品',1,2),"
            "(0,'阴性',2,2);";
        query.exec(sql);

        sql="INSERT INTO ItemCode (Name,Code,DicCode) "
            "VALUES "
            "('A1',1,3),('B1',2,3),('C1',3,3),('D1',4,3),('E1',5,3),('F1',6,3),('G1',7,3),('H1',8,3),"
            "('A2',9,3),('B2',10,3),('C2',11,3),('D2',12,3),('E2',13,3),('F2',14,3),('G2',15,3),('H2',16,3),"
            "('A3',17,3),('B3',18,3),('C3',19,3),('D3',20,3),('E3',21,3),('F3',22,3),('G3',23,3),('H3',24,3),"
            "('A4',25,3),('B4',26,3),('C4',27,3),('D4',28,3),('E4',29,3),('F4',30,3),('G4',31,3),('H4',32,3),"
            "('A5',33,3),('B5',34,3),('C5',35,3),('D5',36,3),('E5',37,3),('F5',38,3),('G5',39,3),('H5',40,3),"
            "('A6',41,3),('B6',42,3),('C6',43,3),('D6',44,3),('E6',45,3),('F6',46,3),('G6',47,3),('H6',48,3),"
            "('A7',49,3),('B7',50,3),('C7',51,3),('D7',52,3),('E7',53,3),('F7',54,3),('G7',55,3),('H7',56,3),"
            "('A8',57,3),('B8',58,3),('C8',59,3),('D8',60,3),('E8',61,3),('F8',62,3),('G8',63,3),('H8',64,3),"
            "('A9',65,3),('B9',66,3),('C9',67,3),('D9',68,3),('E9',69,3),('F9',70,3),('G9',71,3),('H9',72,3),"
            "('A10',73,3),('B10',74,3),('C10',75,3),('D10',76,3),('E10',77,3),('F10',78,3),('G10',79,3),('H10',80,3),"
            "('A11',81,3),('B11',82,3),('C11',83,3),('D11',84,3),('E11',85,3),('F11',86,3),('G11',87,3),('H11',88,3),"
            "('A12',89,3),('B12',90,3),('C12',91,3),('D12',92,3),('E12',93,3),('F12',94,3),('G12',95,3),('H12',96,3);";
        query.exec(sql);

        sql="INSERT INTO ItemCode (IsDefault,Name,Code,DicCode) "
            "VALUES (1,'20','20ul',4),(0,'10','10ul',4),(0,'25','25ul',4),(0,'30','30ul',4);";
        query.exec(sql);

        sql="INSERT INTO ItemCode (Name,Code,DicCode)VALUES "
            "('A1',1,5),('A2',2,5),('A3',3,5),('A4',4,5),"
            "('B1',5,5),('B2',6,5),('B3',7,5),('B4',8,5),"
            "('C1',9,5),('C2',10,5),('C3',11,5),('C4',12,5),"
            "('D1',13,5),('D2',14,5),('D3',15,5),('D4',16,5),"
            "('E1',17,5),('E2',18,5),('E3',19,5),('E4',20,5),"
            "('F1',21,5),('F2',22,5),('F3',23,5),('F4',24,5);";
        query.exec(sql);

        sql="INSERT INTO ItemCode (IsDefault,Name,Code,DicCode) "
            "VALUES (1,'Pcr板',0,6),"
            "(0,'Pcr管',1,6),"
            "(0,'8联排',2,6);";
        query.exec(sql);

        sql="INSERT INTO Settings (ID,param_1,param_2,param_3,param_4,param_5,param_6,param_7,param_8,param_9,param_10,param_11,param_12) "
            "VALUES (1,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(2,0,0,0,0,0,0,0,0,0,0,0,0),(3,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(4,0,0,0,0,0,0,0,0,0,0,0,0),(5,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(6,0,0,0,0,0,0,0,0,0,0,0,0),(7,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(8,0,0,0,0,0,0,0,0,0,0,0,0),(9,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(10,0,0,0,0,0,0,0,0,0,0,0,0),(11,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(12,0,0,0,0,0,0,0,0,0,0,0,0),(13,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(14,0,0,0,0,0,0,0,0,0,0,0,0),(15,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(16,0,0,0,0,0,0,0,0,0,0,0,0),(17,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(18,0,0,0,0,0,0,0,0,0,0,0,0),(19,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(20,0,0,0,0,0,0,0,0,0,0,0,0),(21,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(22,0,0,0,0,0,0,0,0,0,0,0,0),(23,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(24,0,0,0,0,0,0,0,0,0,0,0,0),(25,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(26,0,0,0,0,0,0,0,0,0,0,0,0),(27,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(28,0,0,0,0,0,0,0,0,0,0,0,0),(29,0,0,0,0,0,0,0,0,0,0,0,0),"
            "(30,0,0,0,0,0,0,0,0,0,0,0,0);";
        query.exec(sql);

        sql="INSERT INTO ItemCode (IsDefault,Name,Code,DicCode) "
            "VALUES (1,'FAM','F',7),(0,'SYBR Green','SG',7),"
            "(0,'Eva Green','EG',7),(1,'VIC','V',8),"
            "(0,'HEX','HEX',8),(0,'JOE','JOE',8),(1,'ROX','R',9),"
            "(0,'Texas Red','TR',9),(1,'CY5','C',10),(0,'Qusar 670','Q6',10),"
            "(0,'FAM','F',11),(0,'SYBR Green','SG',11),(0,'Eva Green','EG',11),"
            "(0,'VIC','V',11),(0,'HEX','HEX',11),(0,'JOE','JOE',11),"
            "(0,'ROX','R',11),(0,'Texas Red','TR',11),"
            "(1,'CY5','C',11),(0,'Qusar 670','Q6',11),(1,'明德','1',12),"
            "(1,'./datao','./datao',100);";
        query.exec(sql);

        sql="INSERT INTO DataAnalyseSetting VALUES (0,'三点均值','分析算法2','绝对阈值',0,3,15,3,15,3,15,3,15,10,1);";
        query.exec(sql);

        db.commit();

        // 创建QFile对象，指定文件名
        QFile file("EqptInfo.xml");

        // 尝试打开文件以进行写入
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            qWarning() << "无法打开文件：" << file.errorString();
            return -1;
        }

        // 创建一个QTextStream对象来写入文件
        QTextStream out(&file);

        // 写入XML内容
        out << "<info>" << endl;
        out << "    <operh>00:00</operh>" << endl;//运行时长
        out << "    <operThre>1</operThre>"<<endl;
        out << "    <durah>00:00:00</durah>" << endl;//检测时长
        out << "    <duraThre>00:00:00</duraThre>"<<endl;
        out << "    <times>0</times>" << endl;//实验次数
        out << "    <timesThre>1000</timesThre>"<<endl;
        out << "    <sampelsum>0</sampelsum>" << endl;//总检测样本数
        out << "    <sampelsumThre>460</sampelsumThre>" << endl;
        out << "    <swlife>2.15</swlife>" << endl;
        out << "    <swtimes>3</swtimes>" << endl;
        out << "    <swname>RT-PCR-96 Analysis Software V1.8</swname>" << endl;
        out << "    <steps>30</steps>" << endl;
        out << "    <password>123456</password>" << endl;
        out << "    <serverIp>192.168.0.10</serverIp>" << endl;
        out << "    <serverPort>8081</serverPort>" << endl;
        out << "</info>";

        // 关闭文件
        file.close();
    }

    MainWindow mainW;
    mainW.setWindowTitle(softName);

    setuptotalwind setupW;
    setupW.setWindowTitle(softName);

    setup1Wind setup1W;
    setup1W.setWindowTitle(softName);

    setup2wind setup2W;
    setup2W.setWindowTitle(softName);

    setup3wind setup3W;
    setup3W.setWindowTitle(softName);

    setup4wind setup4W;
    setup4W.setWindowTitle(softName);

    setup5wind setup5W;
    setup5W.setWindowTitle(softName);

    setup6wind setup6W;
    setup6W.setWindowTitle(softName);

    setup7wind setup7W;
    setup7W.setWindowTitle(softName);

    amplprogramwindow amplW;
    amplW.setWindowTitle(softName);

    amplStepWindow amplStepW;
    amplStepW.setWindowTitle(softName);

    SampleWindow sampleW;
    sampleW.setWindowTitle(softName);

    experimentProWindow expW;
    expW.setWindowTitle(softName);

    experimentInfoWindow expInfoW;
    expInfoW.setWindowTitle(softName);

    experimentTemperatureWindow expTempW;
    expTempW.setWindowTitle(softName);

    DataAnalysisWindow analysW;
    analysW.setWindowTitle(softName);

    errmessage errW;
    errW.setWindowTitle(softName);

    maco macoW;
    macoW.setWindowTitle(softName);

    maintainPassword mainPasswordW;
    mainPasswordW.setWindowTitle(softName);


    QObject::connect(&analysW,&DataAnalysisWindow::changeSampleWindow,&analysW,[&](){
        sampleW.showMaximized();
    });

    //主页调转设置页面
    QObject::connect(&mainW,&MainWindow::changeSetUpWindow,&setupW,[&](){
        setupW.showMaximized();
    });

    //设置页面返回主页
    QObject::connect(&setupW,&setuptotalwind::changeMainWindow,&mainW,[&](){
        mainW.showMaximized();
    });

    //主页调转设置页面
    QObject::connect(&mainW,&MainWindow::changeErrorWindow,&errW,[&](){
        errW.showMaximized();
    });

    //设置页面返回主页
    QObject::connect(&errW,&errmessage::changeMainWindow,&mainW,[&](){
        mainW.showMaximized();
    });

    //主页跳转扩展程序页面
    QObject::connect(&mainW,&MainWindow::changeAmplWindow,&amplW,[&](){
        amplW.showMaximized();
    });

    QObject::connect(&mainW,&MainWindow::changeExpTempWindow,&amplW,[&](){
        expTempW.showMaximized();
    });

    QObject::connect(&expTempW,&experimentTemperatureWindow::changeMainWindow,&expTempW,[&](){
        mainW.showMaximized();
    });

    QObject::connect(&amplStepW,&amplStepWindow::changeExpProWindow,&amplStepW,[&](){
        expW.showMaximized();
    });

    //扩展程序返回主页
    QObject::connect(&amplW,&amplprogramwindow::changeMainWindow,&amplW,[&](){
        mainW.showMaximized();
    });

    //扩展程序跳转步骤页面
    QObject::connect(&expW,&experimentProWindow::changeAmplStepWindow,&expW,[&](QString guid){
        amplStepW.amplGuid=guid;
        amplStepW.showMaximized();
    });

    //扩展程序跳转步骤页面
    QObject::connect(&amplW,&amplprogramwindow::changeAmplStepWindow,&amplW,[&](QString guid){
        amplStepW.isReadStatus=0;
        amplStepW.amplGuid=guid;
        amplStepW.showMaximized();
    });

    QObject::connect(&amplW,&amplprogramwindow::changeAmplStepReadWindow,&amplW,[&](QString guid){
        amplStepW.isReadStatus=1;
        amplStepW.amplGuid=guid;
        amplStepW.showMaximized();
    });

    //步骤页面返回扩展程序页面
    QObject::connect(&amplStepW,&amplStepWindow::changeAmplProWindow,&amplStepW,[&](){
        amplW.showMaximized();
    });

    //主页跳转样本页面
    QObject::connect(&mainW,&MainWindow::changeSampleWindow,&mainW,[&](){
        sampleW.showMaximized();
    });

    //主页跳转创建实验页面
    QObject::connect(&mainW,&MainWindow::changeExpInfoWindow,&mainW,[&](){
        expInfoW.showMaximized();
    });

    //样本页面返回主页
    QObject::connect(&sampleW,&SampleWindow::changeMainWindow,&sampleW,[&](){
        mainW.showMaximized();
    });

    QObject::connect(&sampleW,&SampleWindow::changeDataAnalyWindow,&sampleW,[&](){
        analysW.showMaximized();
    });

    //样本页面返回创建实验页
    QObject::connect(&sampleW,&SampleWindow::changeExpInfoWindow,&sampleW,[&](){
        expInfoW.showMaximized();
    });

    //主页跳转样本页面
    QObject::connect(&expInfoW,&experimentInfoWindow::changeSampleWindow,&expInfoW,[&](){
        sampleW.showMaximized();
    });

    //主页跳转创建实验页面
    QObject::connect(&expInfoW,&experimentInfoWindow::changeMainWindow,&expInfoW,[&](){
        mainW.showMaximized();
    });

    QObject::connect(&mainW,&MainWindow::changeExpeWindow,&expW,[&](){
        expW.showMaximized();
    });

    QObject::connect(&expW,&experimentProWindow::changeSampleWindow,&sampleW,[&](){
        sampleW.showMaximized();
    });


    //主页调转实验页面
    QObject::connect(&sampleW,&SampleWindow::changeExpeWindow,&expW,[&](){
        expW.showMaximized();
    });

    //实验页面跳转主页
    QObject::connect(&expW,&experimentProWindow::changeMainWindow,&expW,[&](){
        mainW.showMaximized();
    });

    QObject::connect(&mainW,&MainWindow::changeAnalyWindow,&analysW,[&](){
        analysW.showMaximized();
    });

    QObject::connect(&analysW,&DataAnalysisWindow::changeMainWindow,&analysW,[&](){
        mainW.showMaximized();
    });

    QObject::connect(&setupW,&setuptotalwind::changeSetUp1Window,&setupW,[&](){
        setup1W.showMaximized();
    });

    QObject::connect(&setup1W,&setup1Wind::changeTotalWindow,&setup1W,[&](){
        setupW.showMaximized();
    });

    QObject::connect(&setupW,&setuptotalwind::changeSetUp2Window,&setupW,[&](){
        setup2W.showMaximized();
    });

    QObject::connect(&setup2W,&setup2wind::changeTotalWindow,&setup2W,[&](){
        setupW.showMaximized();
    });

    QObject::connect(&setupW,&setuptotalwind::changeSetUp3Window,&setupW,[&](){
        setup3W.showMaximized();
    });

    QObject::connect(&setup3W,&setup3wind::changeTotalWindow,&setup3W,[&](){
        setupW.showMaximized();
    });

    QObject::connect(&setupW,&setuptotalwind::changeSetUp4Window,&setupW,[&](){
        setup4W.showMaximized();
    });

    QObject::connect(&setup4W,&setup4wind::changeTotalWindow,&setup4W,[&](){
        setupW.showMaximized();
    });

    QObject::connect(&setupW,&setuptotalwind::changeSetUp5Window,&setupW,[&](){
        setup5W.showMaximized();
    });

    QObject::connect(&setup5W,&setup5wind::changeTotalWindow,&setup5W,[&](){
        setupW.showMaximized();
    });

    QObject::connect(&setupW,&setuptotalwind::changeSetUp6Window,&setupW,[&](){
        setup6W.showMaximized();
    });

    QObject::connect(&setup6W,&setup6wind::changeTotalWindow,&setup6W,[&](){
        setupW.showMaximized();
    });

    QObject::connect(&setup6W,&setup6wind::changeAnalyWindow,&analysW,[&](){
        analysW.showMaximized();
    });

    QObject::connect(&setupW,&setuptotalwind::changeSetUp7Window,&setupW,[&](){
        setup7W.showMaximized();
    });

    QObject::connect(&setup7W,&setup7wind::changeTotalWindow,&setup7W,[&](){
        setupW.showMaximized();
    });


    QObject::connect(&analysW,&DataAnalysisWindow::changeExperiInfoWindow,&analysW,[&](){
        expInfoW.showMaximized();
    });

    QObject::connect(&expInfoW,&experimentInfoWindow::changeDataAnalysisWindow,&expInfoW,[&](){
        analysW.showMaximized();
    });

    QObject::connect(&expInfoW,&experimentInfoWindow::changeAmplProgramStepWindow,&expInfoW,[&](QString id){
        amplStepW.isReadStatus=2;
        amplStepW.amplGuid=id;
        amplStepW.showMaximized();
    });

    QObject::connect(&amplStepW,&amplStepWindow::changeExperimentInfoWindow,&amplStepW,[&](){
        expInfoW.showMaximized();
    });

    //主页调转设置页面
    QObject::connect(&mainPasswordW,&maintainPassword::changeMacoWindow,&mainPasswordW,[&](){
        macoW.showMaximized();
    });

    QObject::connect(&mainW,&MainWindow::changeMaintainWindow,&mainW,[&](){
        mainPasswordW.show();
    });

    QObject::connect(&mainPasswordW,&maintainPassword::changeMainWindow,&mainPasswordW,[&](){
        mainW.showMaximized();
    });

    QObject::connect(&macoW,&maco::changeMainWindow,&macoW,[&](){
        mainW.showMaximized();
    });

    sql=QString("Select * from ConnectionInfo ");
    query.exec(sql);

    QString ip="";
    int port=0;
    while (query.next()) {
        ip=query.value("Ip").toString();
        port=query.value("Port").toInt();
    }
    query.clear();

    tcpClient= TcpClient::getInstance();
    tcpClient->ClientConnectToHost(ip, port);

    eqptinfo *eqInfo = new eqptinfo();
    QString serverIp = eqInfo->serverIpRead();
    int serverPort = eqInfo->serverPortRead().toInt();

    TcpServer *server = TcpServer::getInstance();;
    if (!server->listen(QHostAddress::AnyIPv4, serverPort)) {
        qDebug() << "Server could not start!";
    } else {
        qDebug() << "Server started!";
    }

    mainW.showMaximized();


    return a.exec();
}
